#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django import forms
from django.core.exceptions import ValidationError

from app01 import models


class NoticeModelForm(forms.ModelForm):

    class Meta:
        model = models.Notice
        fields = ['title', 'author', 'content']

    def __init__(self, *args, **kwargs):
        super(NoticeModelForm, self).__init__(*args, **kwargs)
        # 统一给ModelForm生成字段添加样式
        for name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'


class NoticeUserModelForm(forms.ModelForm):
    class Meta:
        model = models.Notice
        fields = ['title', 'content']

    def __init__(self, *args, **kwargs):
        super(NoticeUserModelForm, self).__init__(*args, **kwargs)
        # 统一给ModelForm生成字段添加样式
        for name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'


